local prefabs = {}

local assets =
{
    Asset("ANIM", "anim/sw_shadow_crown_equipped.zip"),
}

local function OnActivated(inst, owner, is_front)
    inst.entity:SetParent(owner.entity)
    inst.entity:AddFollower()
    inst.Follower:FollowSymbol(owner.GUID, "hair", 0, 0, 0) -- "swap_hat"

    inst.AnimState:Hide(is_front and "back" or "front")
    inst.AnimState:SetFinalOffset(is_front and 1 or -1)

    inst.AnimState:PlayAnimation("activate_pre")
    inst.AnimState:PushAnimation("activate_loop", true)
end

local function OnDeactivated(inst)
    inst.AnimState:PlayAnimation("activate_pst")
    inst:ListenForEvent("animover", inst.Remove)
end

local function SetSkin(inst, skin_build, GUID)
    inst.AnimState:OverrideItemSkinSymbol("p4_piece", skin_build, "p4_piece", GUID, "sw_shadow_crown_equipped")
    inst.AnimState:OverrideItemSkinSymbol("fx_glow", skin_build, "fx_glow", GUID, "sw_shadow_crown_equipped")
end

local function onturnoff(inst)
end

local function onturnon(inst)
end

local function onactivate(inst)
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    inst.AnimState:SetBank("sw_shadow_crown_equipped")
    inst.AnimState:SetBuild("sw_shadow_crown_equipped")
    inst.AnimState:PlayAnimation("idle", true)
    inst.AnimState:SetFinalOffset(1)
    inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")

    inst.Transform:SetNoFaced()

    inst:AddTag("FX")
    inst:AddTag("DECOR")
    inst:AddTag("ancient_station")
    inst:AddTag("prototyper")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst.persists = false

    inst:AddComponent("prototyper")
    inst.components.prototyper.onturnon = onturnon
    inst.components.prototyper.onturnoff = onturnoff
    inst.components.prototyper.onactivate = onactivate
    inst.components.prototyper.trees = TUNING.PROTOTYPER_TREES.ANCIENTALTAR_HIGH

    inst.SetSkin = SetSkin
    inst.OnActivated = OnActivated
    inst.OnDeactivated = OnDeactivated

    return inst
end

return Prefab("sw_shadow_crown_equipped", fn, assets, prefabs)
